<?php
date_default_timezone_set('Asia/Shanghai');
//session
session_start();
$template_folder = "template";
$application_folder = "application";
$upload_folder = "uploads";

// Path to the application folder
define('APP_PATH', str_replace('\\', '/', SYSTEM_PATH . DIRECTORY_SEPARATOR . $application_folder . DIRECTORY_SEPARATOR));
// The name of THIS file
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
// Path to the template folder
define('TEMPLATE_PATH', str_replace('\\', '/', SYSTEM_PATH . DIRECTORY_SEPARATOR . $template_folder . DIRECTORY_SEPARATOR));

define('UPLOAD_ROOT_PATH', str_replace('\\', '/', ROOT_PATH . DIRECTORY_SEPARATOR . $upload_folder . DIRECTORY_SEPARATOR));

define('POST_HTML_PATH', str_replace('\\', '/', ROOT_PATH . '/p' . DIRECTORY_SEPARATOR));
define('POST_HTML_URI', str_replace('\\', '/', '/p' . DIRECTORY_SEPARATOR));

define('HOME_HTML_PATH', str_replace('\\', '/', ROOT_PATH . '/home' . DIRECTORY_SEPARATOR));
define('HOME_HTML_URI', str_replace('\\', '/', '/home' . DIRECTORY_SEPARATOR));

define('CATEGORY_HTML_PATH', str_replace('\\', '/', ROOT_PATH . '/category' . DIRECTORY_SEPARATOR));
define('CATEGORY_HTML_URI', str_replace('\\', '/', '/category' . DIRECTORY_SEPARATOR));
// run time environment
define('ENVIRONMENT', isset($_SERVER['ENVIRONMENT']) ? $_SERVER['ENVIRONMENT'] : 'development');

//core function load
include_once CORE_PATH . 'core_helper.php';

//set_error_handler('_error_handler');
//set_exception_handler('_exception_handler');

$app_config = array();
switch (ENVIRONMENT) {
case 'product':
	$app_config = include SYSTEM_PATH . '/config/product/app.php';

	break;
case 'testing':
	$app_config = include SYSTEM_PATH . '/config/testing/app.php';

	break;
case 'development':
	if (file_exists(SYSTEM_PATH . '/config/development/app.php')) {
		$app_config = include SYSTEM_PATH . '/config/development/app.php';
	} else {
		$app_config = include SYSTEM_PATH . '/config/app.php';
	}

	break;
default:
	$app_config = include SYSTEM_PATH . '/config/app.php';

	break;
}

define('APP_ADMIN_URI', $app_config['admin_uri']); //自定义管理后台名称

define('APP_CONFIG', $app_config);

// Path to the template folder
define('APP_VIEW', TEMPLATE_PATH . '/' . $app_config['template'] . DIRECTORY_SEPARATOR);

//route to app
core_app_route();
